#pragma once
#include"RBTree2.h"
namespace hjc
{
	template<class K,class V>
	class Mymap
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K, pair<K, V>, MapKeyOfT>::Iterator iterator;
		typedef typename RBTree<K, pair<K, V>, MapkeyOfT>::ConstIterator const_iterator;

		iterator begin()
		{
			return _rbtree.Begin();
		}

		iterator end()
		{
			return _rbtree.End();
		}

		const_iterator begin() const
		{
			return _rbtree.Begin();
		}

		const_iterator end() const
		{
			return _rbtree.End();
		}

		pair<iterator, bool> Insert(const pair<K,V>& kv)
		{
			return _rbtree.Insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = _rbtree.Insert({ key,V() });
			return ret.first->second;
		}


	private:
		RBTree<K, pair<K, V>, MapKeyOfT> _rbtree;

	};
}